#!/usr/bin/env python
# -*- encoding: utf-8 -*-
"""
@Introduce :
@File      : celery.py
@Time      : 2022/2/16 17:58
@Author    : toby
"""

from datetime import timedelta
from celery.schedules import crontab

from celery import Celery

app = Celery('proj',
             broker="redis://localhost:6379/0",
             backend="redis://localhost:6379/1",
             include=['proj.tasks','proj.task2'])

# Optional configuration, see the application user guide.

app.conf.timezone = 'Asia/Shanghai'
# 是否使用UTC
app.conf.enable_utc = False

app.conf.beat_schedule  = {
    'tasks': {
            'task': 'proj.tasks.add',
             # 'schedule': crontab(minute="*/1"),         # 每 30 秒执行一次
            'schedule': timedelta(seconds=20),
            'args': (2,3)                           # 任务函数参数
        },

    'task2': {
            'task': 'proj.task2.add2',
             'schedule': crontab(minute="*/1"),         # 每 30 秒执行一次
            # 'schedule': timedelta(seconds=20),
            'args': (2,4)                           # 任务函数参数
        },

}


if __name__ == '__main__':
    app.start()